using UnityEngine;
using System.Collections;

public class ComponentHealth : MonoBehaviour
{
	[SerializeField]
	protected int MaxHealth = 10;
	
	protected int CurrentHealth;
	protected static int NumAsteroid = 8;
	
	// Getter
	public int CurrHP {	get	{ return CurrentHealth; } }
	public int MaxHP {	get	{ return MaxHealth; } }
	public float FractionHP { get { return (float)(CurrentHealth)/(float)(MaxHealth); } }
	
	void Start()
	{
		CurrentHealth = MaxHealth;
	}
	
	public void Modify(int amount)
	{
		CurrentHealth += amount;
		
		if (CurrentHealth > MaxHealth)
		{
			CurrentHealth = MaxHealth;
		}
		else if (CurrentHealth <= 0)
		{
			Die();
		}
	}
	
	public void Set(int amount)
	{
		CurrentHealth = amount;
		Modify (0); // run thru the checks in Modify()
	}
		
	public void Die()
	{
		if (this.name == "Ship")
		{
			Application.LoadLevel(2);
		}
		else
		{
			Destroy(this.gameObject);
			NumAsteroid--;
			print (NumAsteroid);
			if ( NumAsteroid == 0 )
			{
				Application.LoadLevel(3);
			}
		}
	}
	
	void Update()
	{
		
	}
}
